package com.creditease.cn.monitor.controller;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.creditease.cn.monitor.service.ServerInfoService;

@Controller
@RequestMapping("/serverInfo")
public class ServerInfoController extends BaseController{
	private Logger logger = LoggerFactory.getLogger(ServerInfoController.class);
	@Autowired
	private ServerInfoService serverInfoService;
	
	@RequestMapping(value="/index")
	public String index(){
		return "/serverInfo/serverinfo_index.html";
	}
	
	@RequestMapping(value="/getServerInfo")
	public String getServerInfo(Model model){
		Map<String,Map<String,String>> serverInfo = serverInfoService.getServerInfo();
		
		Map<String,String> serverMap = serverInfo.get("Server");
		Map<String,String> clientsMap = serverInfo.get("Clients");
		Map<String,String> memoryMap = serverInfo.get("Memory");
		Map<String,String> persistenceMap = serverInfo.get("Persistence");
		Map<String,String> replicationMap = serverInfo.get("Stats");
		Map<String,String> statsMap = serverInfo.get("Replication");
		Map<String,String> CPUMap = serverInfo.get("CPU");
		Map<String,String> clusterMap = serverInfo.get("Cluster");
		Map<String,String> keyspaceMap = serverInfo.get("Keyspace");
		
		model.addAttribute("serverMap", serverMap);
		model.addAttribute("clientsMap", clientsMap);
		model.addAttribute("memoryMap", memoryMap);
		model.addAttribute("persistenceMap", persistenceMap);
		model.addAttribute("replicationMap", replicationMap);
		model.addAttribute("statsMap", statsMap);
		model.addAttribute("CPUMap", CPUMap);
		model.addAttribute("clusterMap", clusterMap);
		model.addAttribute("keyspaceMap", keyspaceMap);
		
		logger.info("读取服务器信息 ：" + serverInfo);
		return "/serverInfo/serverinfo_index.html";
	}
	
	@RequestMapping(value="/getServerConfig")
	public String getServerConfig(Model model){
		Map<String,String> serverConfigMap = serverInfoService.getServerConfig();
		model.addAttribute("serverConfigMap", serverConfigMap);
		logger.info("读取服务器的配置信息 ：" + serverConfigMap);
		return "/serverInfo/serverinfo_config.html";
	}
}
